using Admin2025.Application.Events;
using MediatR;
using Microsoft.Extensions.Logging;

namespace Admin2025.Application.EventHandlers;

/// <summary>
/// 用户创建事件处理器 - 记录审计日志
/// </summary>
public class UserCreatedAuditHandler : INotificationHandler<UserCreatedNotification>
{
    private readonly ILogger<UserCreatedAuditHandler> _logger;

    public UserCreatedAuditHandler(ILogger<UserCreatedAuditHandler> logger)
    {
        _logger = logger;
    }

    public async Task Handle(UserCreatedNotification notification, CancellationToken cancellationToken)
    {
        var userEvent = notification.UserCreatedEvent;
        
        _logger.LogInformation("用户创建审计: 事件ID={EventId}, 用户ID={UserId}, 用户名={Username}, 昵称={Nickname}, 部门ID={DepartmentId}, 创建时间={OccurredOn}",
            userEvent.EventId,
            userEvent.UserId,
            userEvent.Username,
            userEvent.Nickname,
            userEvent.DepartmentId,
            userEvent.OccurredOn);

        // 这里可以记录到审计日志表
        await Task.CompletedTask;
    }
}
